package net.valyrian.game.pantallaInicio;

import tween.SpriteAccessor;
import aurelienribon.tweenengine.BaseTween;
import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenCallback;
import aurelienribon.tweenengine.TweenManager;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.loaders.SoundLoader;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class PantallaInicio implements Screen {
	
	private SpriteBatch batch;
	private Sprite splash;
	private TweenManager tweenManager;
	private Sound sound;
	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(0, 0, 0, 1);
		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		
		
		batch.begin();
		splash.draw(batch);
		batch.end();
		
		tweenManager.update(delta);
	}

	@Override
	public void resize(int width, int height) {
		splash.setBounds(0, 0, width, height);
		splash.setSize(width, height);

	}

	@Override
	public void show() {
		sound = Gdx.audio.newSound(Gdx.files.internal("audio/splash_sound.mp3"));
		batch = new SpriteBatch();
		tweenManager = new TweenManager();
		Tween.registerAccessor(Sprite.class, new SpriteAccessor());
		
		Texture splashTexture= new Texture("img/ValyrianLogo.png");
		splash = new Sprite(splashTexture);
		splash.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		sound.play(0.7f);
		Tween.set(splash, SpriteAccessor.ALPHA).target(0).start(tweenManager);
		//Tween.to(splash, SpriteAccessor.ALPHA, 2).target(1).repeatYoyo(1, 2).start(tweenManager);
		Tween.to(splash, SpriteAccessor.ALPHA, 3.5f).target(1).repeatYoyo(1, 1).setCallback(new TweenCallback() {
			
			@Override
			public void onEvent(int type, BaseTween<?> source) {
			((Game) Gdx.app.getApplicationListener()).setScreen(new MainMenu());				
			}
		}).start(tweenManager);
		
		tweenManager.update(Float.MIN_VALUE);
		}

	@Override
	public void hide() {
		dispose();

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		batch.dispose();
		splash.getTexture().dispose();
		sound.dispose();

	}

}
